package com.ruoyi.business.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.business.domain.BizBind;
import com.ruoyi.business.domain.BizPlan;
import com.ruoyi.business.domain.BizScore;
import com.ruoyi.business.domain.BizUser;
import com.ruoyi.business.mapper.BizLightMapper;
import com.ruoyi.business.mapper.BizScoreMapper;
import com.ruoyi.common.db.BaseService;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * <pre>
 *
 * </pre>
 *
 * @author zhangli
 * @since 2023/10/22
 */
@Component
public class BizScoreDataService extends BaseService<Integer, BizScore> {


    public List<BizScore> getAllByUserNumber(String userNumber,String className){
        QueryWrapper<BizScore> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_number",userNumber);
        queryWrapper.eq("class_name",className);

        return selectList(queryWrapper);
    }

    public List<BizScore> getAllByUserNumber(String userNumber,String className,int weekNum){
        QueryWrapper<BizScore> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_number",userNumber);
        queryWrapper.eq("week_num",weekNum);
        queryWrapper.eq("class_name",className);
        queryWrapper.orderByAsc("checkin_date");

        return selectList(queryWrapper);
    }

    public List<BizScore> getAllByUserNumber(String userNumber, String className, Date start,Date end){
        QueryWrapper<BizScore> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_number",userNumber);
        queryWrapper.eq("class_name",className);
        queryWrapper.le("checkin_date", end);
        queryWrapper.ge("checkin_date", start);
        queryWrapper.orderByAsc("checkin_date");

        return selectList(queryWrapper);
    }

    public int getStudyLevel(double score){
        return ((BizScoreMapper)getDbService().getBaseMapper()).selectTop(score) + 1;
    }

    public int getTotalPerson(){
        return ((BizScoreMapper)getDbService().getBaseMapper()).selectTotalPerson();
    }

}
